package LOGISTICS;


import java.net.InetAddress;
import java.net.UnknownHostException;

import TOOLS.SQLtool;

public class test001_newDB {

	public static void main(String[] args) {
		SQLtool sql=new SQLtool();
		String IPaddr="192.168.0.1";
		try {
			InetAddress addr = InetAddress.getLocalHost();
			IPaddr=addr.getHostAddress();
		} catch (UnknownHostException e1) {
			e1.printStackTrace();
		}
		sql.config(IPaddr, "AKS2019", "sa", "123456");
//		sql.config("192.168.0.39", "AKS2019", "sa", "abcd1234!");
//		sql.config("192.168.1.97", "XHAKS2021", "ma", "123456");
		try {
			sql.connect();
//			c_material cm=new c_material(sql);
//			c_materialType cmt=new c_materialType(sql);
//			cm.newDBsheet();
//			cmt.newDBsheet();
//			cm.newDBview();
//			cmt.newDBview();

			String tableName="[dbo].[setupLocation_resouce]";
			String sqlStr="IF OBJECT_ID('"+tableName+"', 'U') IS NOT NULL DROP TABLE "+tableName;
			tableName="[dbo].[shelfList]";
			sqlStr="IF OBJECT_ID('"+tableName+"', 'U') IS NOT NULL DROP TABLE "+tableName;
			try {
				sql.Command(sqlStr);
			} catch (Exception e) {
				if(e.getMessage().equals("-11")) {
					;
				}else {
					throw e;
				}
			}
			
			sqlStr="CREATE TABLE "+tableName+" (\r\n" + 
					"[shelfListIndex] int IDENTITY(1,1) NOT NULL UNIQUE,\r\n" + 
					"[shelfNumber] varchar(100) NOT NULL,\r\n" + 
					"[x] varchar(50) DEFAULT 2,\r\n" + 
					"[y] varchar(50) DEFAULT 2,\r\n" + 
					"[w] varchar(50) DEFAULT 2,\r\n" + 
					"[h] varchar(50) DEFAULT 2,\r\n" + 
					"[cells] varchar(300) NULL,\r\n" + 
					"[lastEdit] datetime DEFAULT GETDATE(),\r\n" + 
					"[createTime] datetime DEFAULT GETDATE() \r\n" + 
					")";
			sql.Command(sqlStr);

		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}
